package org.jeecg.modules.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dingtalk.api.request.OapiProcessinstanceGetRequest;
import com.dingtalk.api.response.OapiProcessinstanceGetResponse;
import com.dingtalk.api.response.OapiUserGetResponse;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.jeecg.common.api.ding.DingApi;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.RoleInfo;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.config.CallBackEvent;
import org.jeecg.modules.config.Constant;
import org.jeecg.modules.config.URLConstant;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiCallBackDeleteCallBackRequest;
import com.dingtalk.api.request.OapiCallBackRegisterCallBackRequest;
import com.dingtalk.api.response.OapiCallBackRegisterCallBackResponse;
import com.dingtalk.oapi.lib.aes.DingTalkEncryptor;
import com.dingtalk.oapi.lib.aes.Utils;
import org.jeecg.modules.cwysp.service.IDiyCwyspService;
import org.jeecg.modules.dinguser.service.IDiyDingUserService;
import org.jeecg.modules.entity.DiyProfessorInfo;
import org.jeecg.modules.entity.DiyProjectOwnProfessorType;
import org.jeecg.modules.entity.DiyProjectProfessor;
import org.jeecg.modules.entity.ProjectProfessorInfo;
import org.jeecg.modules.pinkun.entity.DiyPinkun;
import org.jeecg.modules.pinkun.service.IDiyPinkunService;
import org.jeecg.modules.service.*;
import org.jeecg.modules.service.impl.ProjectOwnProfessorServiceImpl;
import org.jeecg.modules.smartSchoolFiancial.service.ISmartSchoolFiancialService;
import org.jeecg.modules.smartSchoolScholarship.service.ISmartSchoolScholarshipService;
import org.jeecg.modules.smartSchoolStudentLeave.service.ISmartSchoolStudentLeaveService;
import org.jeecg.modules.smartSchoolTeacherLeave.service.ISmartSchoolTeacherLeaveService;
import org.jeecg.modules.smartSchoolliuixao.service.ISmartSchoolJiaqiliuxiaoService;
import org.jeecg.modules.smartStudent.service.ISmartStudentTeacherInfomationService;
import org.jeecg.modules.smartTeacher.service.ISmartSchoolTeacherInfomationService;
import org.jeecg.modules.smartschoolpoverty.service.ISmartSchoolPovertyService;
import org.jeecg.modules.student.service.IDiyStudentService;
import org.jeecg.modules.teacher.service.IDiyTescherService;
import org.jeecg.modules.temporary.entity.DiyTemporaryApplicantInfo;
import org.jeecg.modules.temporary.service.impl.DiyTemporaryApplicantInfoServiceImpl;
import org.jeecg.modules.util.*;
import org.jeecg.modules.vo.ProfessorChoose;
import org.jeecg.modules.xsqj.service.IXsqjService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * E应用回调信息处理
 */
@Slf4j
@RestController
public class CallbackController {

    private static final Logger bizLogger = LoggerFactory.getLogger("BIZ_CALLBACKCONTROLLER");
    private static final Logger mainLogger = LoggerFactory.getLogger(CallbackController.class);

    /**
     * 创建套件后，验证回调URL创建有效事件（第一次保存回调URL之前）
     */
    private static final String CHECK_URL = "check_url";

    /**
     * 审批任务回调
     */
    private static final String BPMS_TASK_CHANGE = "bpms_task_change";

    /**
     * 审批实例回调
     */
    private static final String BPMS_INSTANCE_CHANGE = "bpms_instance_change";

    /**
     * 相应钉钉回调时的值
     */
    private static final String CALLBACK_RESPONSE_SUCCESS = "success";


    private static RestTemplate restTemplate;
    @Autowired
    public  void setRestTemplate(RestTemplate restTemplate) {
        CallbackController.restTemplate = restTemplate;
    }
    @Autowired
    private CallbackService callbackService;
    @Autowired
    ProjectOwnProfessorServiceImpl projectOwnProfessorService;
    @Autowired
    private IDiyProfessorInfoService iDiyProfessorInfoService;
    @Autowired
    private  RedisTemplate redisTemplate;
    @Autowired
    private IDiyDingUserService dingUserService;
    @Autowired
    private IProjectProfessorInfoService projectProfessorInfoService;
    @Autowired
    private IDiyProjectProfessorService diyProjectProfessorService;
    @Autowired
    ISysBaseAPI iSysBaseAPI;
    @Autowired
    private IDiyProjectOwnProfessorTypeService diyProjectOwnProfessorTypeService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private DiyTemporaryApplicantInfoServiceImpl diyTemporaryApplicantInfoService;
    @Autowired
    private IDiyDingUserService diyDingUserService;
    @Autowired
    private IDiyPinkunService diyPinkunService;
    @Autowired
    private IDiyStudentService studentService;
    @Autowired
    private IDiyTescherService tescherService;
    @Autowired
    private IDiyCwyspService cwyspService;
    @Autowired
    private IXsqjService xsqjService;
    @Autowired
    private DingApi dingApi;
    @Autowired
    private ISysBaseAPI sysBaseAPI;
    @Autowired
    private ISmartStudentTeacherInfomationService smartStudentTeacherInfomationService;
    @Autowired
    private ISmartSchoolTeacherInfomationService smartSchoolTeacherInfomationService;
    @Autowired
    private ISmartSchoolPovertyService smartSchoolPovertyService;
    @Autowired
    private ISmartSchoolFiancialService smartSchoolFiancialService;
    @Autowired
    private ISmartSchoolScholarshipService smartSchoolScholarshipService;
    @Autowired
    private ISmartSchoolStudentLeaveService smartSchoolStudentLeaveService;
    @Autowired
    private ISmartSchoolTeacherLeaveService smartSchoolTeacherLeaveService;
    @Autowired
    private ISmartSchoolJiaqiliuxiaoService smartSchoolJiaqiliuxiaoService;

    /**
     * 回调函数
     *
     * @param signature
     * @param timestamp
     * @param nonce
     * @param json
     * @return
     */
    @RequestMapping(value = "/callback", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, String> callback(@RequestParam(value = "signature", required = false) String signature,
                                        @RequestParam(value = "timestamp", required = false) String timestamp,
                                        @RequestParam(value = "nonce", required = false) String nonce,
                                        @RequestBody(required = false) JSONObject json,
                                        HttpServletRequest request) {
        String params = " signature:" + signature + " timestamp:" + timestamp + " nonce:" + nonce + " json:" + json;
        try {
            //当使用文档中的方式接收钉钉推送的订阅事件时，是以应用为维度推送的，corpidOrSuiteKey为应用的AppKey，可在开发者后台的应用详情页面中获取。
            //当使用HTTP回调注册接口方式接收钉钉推送的订阅事件时，是以企业为维度推送的，corpidOrSuiteKey为CorpId。
            DingTalkEncryptor dingTalkEncryptor = new DingTalkEncryptor(Constant.TOKEN, Constant.ENCODING_AES_KEY, Constant.APPKEY);

            //从post请求的body中获取回调信息的加密数据进行解密处理
            String encryptMsg = json.getString("encrypt");
            String plainText = dingTalkEncryptor.getDecryptMsg(signature, timestamp, nonce, encryptMsg);
            JSONObject obj = JSON.parseObject(plainText);

            //当前的审批id
            String processInstanceId = obj.getString("processInstanceId");
            //审批结果。同意：agree;拒绝：refuse;转送：redirect(当前值只有bpms_task_change能够接收到)
            String result = obj.getString("result");
            // 获取审批模板id
            String processCode = obj.getString("processCode");
            //获取回调数据类型
            String eventType = obj.getString("EventType");

            if (BPMS_TASK_CHANGE.equals(eventType)) {
                // 收到审批任lo务进度
                bizLogger.info("收到审批任务进度更新: " + plainText);
                String body = callbackService.getInfoById(processInstanceId);
                // 转为json对象
                JSONObject object = JSON.parseObject(body);
                //todo: 实现审批的业务逻辑，如发消息
                String process_instance = object.getString("process_instance");
                JSONObject object2 = JSON.parseObject(process_instance);
                //发起人id
                String originator_userid = object2.getString("originator_userid");
                //获取已审批任务列表
                String tasks = object2.getString("tasks");
                JSONArray array = JSON.parseArray(tasks);
                tasks = array.get(0).toString();
                JSONObject object3 = JSON.parseObject(tasks);
                //获取操作人的id
                String userid = object3.getString("userid");
                JSONObject obj1 = new JSONObject();
                OapiUserGetResponse userProfile = UserUtil.getUserProfile(AccessTokenUtil.getToken(), userid);
                String mobileNum = userProfile.getMobile();
                obj1.put("name", "您钉钉上有审批任务请及时处理");
//              DySmsHelper.sendSms(mobileNum,obj1, DySmsEnum.DING_TMPLATE_CODE);
            }
            else if (BPMS_INSTANCE_CHANGE.equals(eventType)) {
                // 审批实例状态更新
                bizLogger.info("收到审批实例状态更新: " + plainText);
                // 调用接口获取审批表单的信息,并且转为json对象
                String body = callbackService.getInfoById(processInstanceId);
                JSONObject bodyJson = JSON.parseObject(body);
                //获取审批实例详情
                JSONObject process_instance = bodyJson.getJSONObject("process_instance");
                //获取发起人的userid
                String originator_userid = process_instance.getString("originator_userid");
                //获取表单详情列表
                JSONArray form_component_values = process_instance.getJSONArray("form_component_values");
                //同意
                if (obj.containsKey("result") && "agree".equals(result)){
                    switch (processCode){
                        case Constant.POVERTY_RECOGNITION_APPLICATION :
                            System.out.println("贫困认定");
                            smartSchoolPovertyService.saveAllInfo(form_component_values);
                            break;
                        case Constant.STUDENT_INFO_UPDATE_OR_INSERT:
                            System.out.println("学生信息调整");
                            smartStudentTeacherInfomationService.saveOrUpdateInfo(form_component_values,originator_userid);
                            break;
                        case Constant.TEACHER_INFO_UPDATE_OR_INSERT:
                            System.out.println("老师信息调整");
                            smartSchoolTeacherInfomationService.saveOrUpdateInfo(form_component_values,originator_userid);
                            break;
                        case Constant.CWYSP:
                            System.out.println("财务预审批");
                            smartSchoolFiancialService.saveOrUpdateInfo(form_component_values,originator_userid);
                            break;
                        case Constant.SMART_SCHOOL_SCHOLARSHIP:
                            System.out.println("奖学金管理");
                            smartSchoolScholarshipService.saveOrUpdateInfo(form_component_values,originator_userid);
                            break;
                        case Constant.XUESHENG_QINGJIA:
                            System.out.println("学生请假管理");
                            smartSchoolStudentLeaveService.saveOrUpdateInfo(form_component_values,originator_userid);
                            break;
                        case Constant.JIAOSHI_QINGJIA:
                            System.out.println("教师请假");
                            smartSchoolTeacherLeaveService.saveOrUpdateInfo(form_component_values,originator_userid);
                            break;
                        case Constant.JIAOSHI_XIAOJIA:
                            System.out.println("教师销假");
                            smartSchoolTeacherLeaveService.xiaojia(form_component_values,originator_userid);
                            break;
                        case Constant.XUESHENG_XIOAJIA:
                            System.out.println("学生销假");
                            smartSchoolStudentLeaveService.xiaojia(form_component_values,originator_userid);
                            break;
                        case Constant.JIAQI_LIUXIAO:
                            System.out.println("学生假期留校");
                            smartSchoolJiaqiliuxiaoService.saveOrUpdateInfo(form_component_values,originator_userid);
                            break;
                    }
                }
                //拒绝
                else if ("refuse".equals(result)){
                }
            }
            else if (CallBackEvent.USER_ADD_ORG.equals(eventType)) {
                //用户加入组织
                // 获取用户userid
                bizLogger.info("收到新增用户信息: " + plainText);
                String UserId = obj.getString("UserId");
                JSONArray js = JSONArray.parseArray(UserId);
                UserId = js.get(0).toString();
                // 保存用户的信息
                System.out.println("新增用户的userid"+UserId);
                diyDingUserService.toSaveDingUserInfo(UserId);

            }
            else if (CallBackEvent.USER_LEAVE_ORG.equals(eventType)) {
                // 用户退出组织
                bizLogger.info("收到用户离职信息: " + plainText);
                String UserId = obj.getString("UserId");
                JSONArray js = JSONArray.parseArray(UserId);
                UserId = js.get(0).toString();
                //根据userid删除sys_user表中信息
                sysBaseAPI.deleteSysUserByUnionid(UserId);
                log.info("用户离职成功，数据删除成功");
            }
            else {
                System.out.println("其他类型事件回调");
            }
            // 返回success的加密信息表示回调处理成功
            return dingTalkEncryptor.getEncryptedMap(CALLBACK_RESPONSE_SUCCESS, System.currentTimeMillis(), Utils.getRandomStr(8));
        } catch (Exception e) {
            // 失败的情况，应用的开发者应该通过告警感知，并干预修复
            mainLogger.error("process callback failed！" + params, e);
            return null;
        }

    }


    @PostMapping(value = "/sendToDing2")
    public Result<?> sendToCheck2(@RequestBody DiyTemporaryApplicantInfo diyTemporaryApplicantInfo) throws com.baomidou.mybatisplus.extension.exceptions.ApiException {
        Subject subject = SecurityUtils.getSubject();
        LoginUser user = (LoginUser) subject.getPrincipal();
        log.info(user.toString());
        String username = user.getUsername();
        String jsonStr = callbackService.selUserIdByUnionid(username);
        JSONObject getUserId = JSON.parseObject(jsonStr);
        String userid = getUserId.getString("userid");
        try {
            System.out.println(diyTemporaryApplicantInfo);
            callbackService.sendToDingTalk(diyTemporaryApplicantInfo, userid);
            // 修改专家信息表状态为不可修改
            UpdateWrapper<DiyProfessorInfo> wrapper = new UpdateWrapper<>();
            wrapper.set("is_change_info",0).eq("ding_user_id",userid);
            iDiyProfessorInfoService.update(wrapper);
            return Result.ok("已发送至审核！");
        } catch (Exception e) {
            return Result.error("出错了！请重新发送");
        }
    }
    @PostMapping(value = "/sendToDing")
    public Result<?> sendToCheck(@RequestBody DiyTemporaryApplicantInfo diyTemporaryApplicantInfo, HttpServletRequest request) throws com.baomidou.mybatisplus.extension.exceptions.ApiException {
        Subject subject = SecurityUtils.getSubject();
        LoginUser user = (LoginUser) subject.getPrincipal();
        log.info(user.toString());

        //获取token
        String token = request.getHeader("X-Access-Token");
        //获取当前登录用户的unionid username就是unionid
        String username = JwtUtil.getUsername(token);
        // 获取其中的所有数据，放到钉钉表单中
        System.out.println("sendToCheck ==>  diyProfessorInfo ==>  " + diyTemporaryApplicantInfo);
        // 根据unionid获取userid
        String useridStr = callbackService.selUserIdByUnionid(username);
        JSONObject getUserId = JSON.parseObject(useridStr);
        String userid = getUserId.getString("userid");
        diyTemporaryApplicantInfo.setDingUserId(userid);
        //将表单数据存入数据库中
        //将原有的信息删除
        diyTemporaryApplicantInfoService.delete(userid);
        //添加上最新的临时申请人的信息
        diyTemporaryApplicantInfoService.inset(diyTemporaryApplicantInfo);
        try {
            callbackService.sendToDingTalk(diyTemporaryApplicantInfo,userid);
            return Result.ok("已发送至审核！");
        } catch (Exception e) {
            return Result.error("出错了！请重新发送");
        }
    }

    @GetMapping("/sendAdminErrorList/{errorList}")
    public Result<?> sendAdminErrorList(@PathVariable("errorList") List<String> errorList, HttpServletRequest request) {
        //获取token
        String token = request.getHeader("X-Access-Token");
        //获取当前登录用户的unionid username就是unionid
        String username = JwtUtil.getUsername(token);
        // 获取当前登录用户的unionid username就是unionid
        String originatorUserId = null;
        if (username != null) {
            originatorUserId = UserUtil.unionIdChageUserId(username);
        }
        if (originatorUserId == null) {
            originatorUserId = (String) redisUtil.get("originator_userid");
        }
        //发送项目中哪个类型的专家剩余人数不足
        DingMessageUtil.sendMessageToOriginator(originatorUserId, errorList);
        return Result.ok("人数不够！");
    }

    @RequestMapping("/sendProfessorChooseToDing/{projectId}")
    public Result<?> sendProfessorChooseToDing(@PathVariable("projectId") String projectId, HttpServletRequest request) {
        QueryWrapper<DiyProjectProfessor> wrapper = Wrappers.query();
//        List<String> excludeStates = new ArrayList<>();
//        excludeStates.add("1");//排除已经同意的
//        excludeStates.add("0");//排除已经拒接的
//        excludeStates.add("2");//排除正在考虑的
//        excludeStates.add("-3");//排除被管理员删除的
//        excludeStates.add("-4");//排除临时请假的
        String[] exclude = new String[]{"0", "1", "2", "-4", "-3"};
        wrapper.eq("project_id", projectId).notIn("professor_in_project_states", exclude);
        //查找该项目未被抽取的专家的所有专家
        List<DiyProjectProfessor> list = diyProjectProfessorService.list(wrapper);
        //获取token
        String token = request.getHeader("X-Access-Token");
        //获取当前登录用户的unionid username就是unionid
        String username = JwtUtil.getUsername(token);
        // 获取当前登录用户的unionid username就是unionid
        String originatorUserId = null;
        if (username != null) {
            originatorUserId = UserUtil.unionIdChageUserId(username);
        }
        if (originatorUserId == null) {
            originatorUserId = (String) redisUtil.get("originator_userid");
        }
        if (list.size() > 0) {
            ProjectProfessorInfo projectProfessorInfo = projectProfessorInfoService.getById(projectId);
            ProfessorChoose professorChoose = new ProfessorChoose();
            // 赋值到专门发送到钉钉审批里的vo包下的类
            professorChoose.setProjectId(projectProfessorInfo.getId());
            professorChoose.setProjectName(projectProfessorInfo.getProjectName());
            professorChoose.setProjectType(projectProfessorInfo.getProjectType());
            professorChoose.setProfessorJoinMeetingTime(projectProfessorInfo.getProfessorWorkBeginTime());
            professorChoose.setProfessorJoinMeetingAddress(projectProfessorInfo.getProfessorWorkAddress());
            professorChoose.setProjectFrom(projectProfessorInfo.getProjectFrom());
            professorChoose.setProjectExpectTime(projectProfessorInfo.getProjectExpectTime());
            professorChoose.setProjectAmount(projectProfessorInfo.getProjectAmount());

            for (DiyProjectProfessor professor : list) {
                UpdateWrapper<DiyProjectProfessor> updateWrapper = new UpdateWrapper<>();
                //将专家在项目中的状态改为考虑中
                updateWrapper.eq("project_id", projectId).
                        eq("ding_user_id", professor.getDingUserId()).
                        set("professor_in_project_states", 2);
                diyProjectProfessorService.update(null, updateWrapper);
                // 给专家推送消息
                callbackService.sendProfessorChooseToDingTalk(professorChoose, originatorUserId, professor.getDingUserId());
            }
            projectProfessorInfoService.update(new UpdateWrapper<ProjectProfessorInfo>().lambda().
                    eq(ProjectProfessorInfo::getId, projectId).
                    set(ProjectProfessorInfo::getProjectStatus, ProjectProfessorInfo.projectStage.RUNNING));
            return Result.ok("已发送至审核！");
        } else {
            return Result.ok("人数不够！");
        }
    }

    @RequestMapping("/sendLeaveCause")
    public Result<?> sendLeaveCauseToDing(@RequestBody JSONObject jsonObject){
        Result<?> result = new Result();
        //调用业务层，发送到钉钉上
        try {
            callbackService.sendLeaveCauseToDing(jsonObject);
            result.setSuccess(true);
            result.setMessage("发送成功");
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("发送失败");
            e.printStackTrace();
        }
        return result;
    }


    /**
     * 注册审批，默认执行
     *
     * @throws Exception
     */
    public static void registerCallbackForDD() throws Exception {
        // 先删除企业已有的回调
        DingTalkClient client = new DefaultDingTalkClient(URLConstant.DELETE_CALLBACK);
        OapiCallBackDeleteCallBackRequest request = new OapiCallBackDeleteCallBackRequest();
        request.setHttpMethod("GET");
        client.execute(request, AccessTokenUtil.getToken());

        // 重新为企业注册回调
        client = new DefaultDingTalkClient(URLConstant.REGISTER_CALLBACK);
        OapiCallBackRegisterCallBackRequest registerRequest = new OapiCallBackRegisterCallBackRequest();
        registerRequest.setUrl(Constant.CALLBACK_URL_HOST + "/jeecg-boot" + "/callback");
        registerRequest.setAesKey(Constant.ENCODING_AES_KEY);
        registerRequest.setToken(Constant.TOKEN);

        /*
         * ["bpms_instance_change","bpms_task_change","user_add_org","user_leave_org"]
         * 123456
         * xxxxxxxxlvdhntotr3x9qhlbytb18zyz5zxxxxxxxxx
         * http://182.92.159.117:8080/jeecg-boot/callback
         */

        registerRequest.setCallBackTag(Arrays.asList("bpms_instance_change", "bpms_task_change", CallBackEvent.USER_ADD_ORG, CallBackEvent.USER_LEAVE_ORG));
        OapiCallBackRegisterCallBackResponse registerResponse = client.execute(registerRequest, AccessTokenUtil.getToken());
        if (registerResponse.isSuccess()) {
            System.out.println("回调注册成功了！！！");
        }else{
            System.out.println("回调注册失败了！！！");
        }
    }


    /**
     * 测试
     *
     * @param args
     */
    public static void main(String[] args) {
        try {
            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/get");
            OapiProcessinstanceGetRequest req = new OapiProcessinstanceGetRequest();
            req.setProcessInstanceId("8a45listByProfessorId5ff0-a9c3-4f70-81a3-80473349643e");
            OapiProcessinstanceGetResponse rsp = client.execute(req, "365fb9e06f8638c49fc64fd9b39365ab");
            String bd = rsp.getBody();

            String string = JSON.toJSONString(bd);

            JSONObject object = JSON.parseObject(bd);


            String process_instance = object.getString("process_instance");
            System.out.println("process_instance = " + process_instance);
            JSONObject object1 = JSON.parseObject(process_instance);
            String form_component_values = object1.getString("form_component_values");
            System.out.println("form_component_values = " + form_component_values);
            JSONArray objects = JSON.parseArray(form_component_values);
            // 初始化专家信息对象

            DiyProfessorInfo diyProfessorInfo = new DiyProfessorInfo();
            JSONObject jsonObject = null;

            //遍历
            for (int i = 0; i < objects.size(); i++) {
                jsonObject = objects.getJSONObject(i);
                String name = jsonObject.getString("name");
                String value = jsonObject.getString("value");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            }
            System.out.println(diyProfessorInfo);

        } catch (ApiException e) {
            e.printStackTrace();
        }
    }

    /**
     * 随机抽取一位同类型的专家
     * @param projectId 项目id
     * @param originator_userid  当前审批的发起人
     * @param userid 当前审批的操作者
     * @param request
     */
    public static void randmeOneChooseProfessor(String projectId,String originator_userid,String userid,HttpServletRequest request){
        String url = "http://312730ua54.51vip.biz" + request.getContextPath() + "/projectProfessorInfo/randomOneChoose/" + projectId + "/" + originator_userid + "/" +
                userid + "/" + true;
        System.out.println(url);
        restTemplate.delete(url);
    }


}
